#include<iostream>
using namespace std;
typedef long long LL;
LL n, k;
int main()
{
	cin >> n >> k;
	LL ans = 1;
	for (int i = 1; i < n; i++) {
		ans *= (k - 1);
	}
	cout << k * ans << endl;
	return 0;
}